var canUse = false;
var hasDetected = false;

function _detectWebp() {
    try {
        var canvasEl = document.createElement('canvas');
        if(canvasEl.getContext && canvasEl.getContext('2d')) {
            canUse = canvasEl.toDataURL('image/webp').indexOf('data:image/webp') === 0
        }
    }catch(error) {
        console.log(error)
    }finally {
        hasDetected = true
    }
}

var canUseWebp = function () {
    if(!hasDetected) {
        return _detectWebp()
    }
    return canUse;
}